package com.example.yingjiguanli_demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.yingjiguanli_demo.pojo.Options;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface OptionsMapper extends BaseMapper<Options> {
    /**
     * 批量插入
     * @param options 批量插入的选项
     */
    @Insert({
            "<script>",
            "INSERT INTO options (question_id, option_text, option_label, is_correct) VALUES ",
            "<foreach collection='options' item='item' separator=','>",
            "(#{item.questionId}, #{item.optionText}, #{item.optionLabel}, #{item.isCorrect})",
            "</foreach>",
            "</script>"
    })
    void insertBatchOptions(@Param("options") List<Options> options);

    /**
     * 根据题目ID查询选项
     * @param questionId 题目ID
     * @return 选项列表
     */
    @Select("SELECT * FROM options WHERE question_id = #{questionId}")
    List<Options> getOptionsByQuestionId(@Param("questionId") int questionId);


}
